package com.cssiot.webApi.web;

import java.util.List;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.cssiot.webApi.config.PropertySourceConfig;
import com.cssiot.webApi.entity.UserEntity;
import com.cssiot.webApi.entity.UserTest;
import com.cssiot.webApi.service.UserTestService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@RestController
@Api("使用mybatis")
@RequestMapping("/test")
public class UserController2 {
	private  static Logger log=Logger.getLogger(UserController2.class);
	
@Resource
private  PropertySourceConfig PC;
	@Autowired
	private UserTestService user1Mapper;
	@ApiOperation(value="查询所有用户", notes="整合分页插件pagehelper+Swagger2构建RESTful API文档")
	@GetMapping("/getUsers")
	public List<UserTest>  getUsers() {
		List<UserTest> users = user1Mapper.findAll(UserTest.class);
		log.debug("jacking--test");
		System.out.println(PC);
		return users;
	}
	@ApiOperation(value="根据id查询用户", notes="查询单用户")
//    @ApiImplicitParam(name = "id", value = "用户ID", required = true, dataType = "Long")
	@GetMapping("/getUser/{id}")
	public UserEntity getUser(@PathVariable("id") String id) {
		UserEntity user = (UserEntity) user1Mapper.findById(id);
		return user;
	}

	@ApiOperation(value="新增用户", notes="新增用户")
//	@ApiImplicitParam(name = "id", value = "用户ID", required = true, dataType = "Long")
	@PostMapping("/add")
	public void save(UserTest user) {
		user1Mapper.saveObject(user);
	}
	@ApiOperation(value="根据数据修改用户", notes="修改用户")
//	@ApiImplicitParam(name = "id", value = "用户ID", required = true, dataType = "json")
	@PutMapping(value = "update")
	public void update(UserTest user) {
		user1Mapper.updateObject(user);
	}
 
	@ApiOperation(value="根据id删除用户", notes="删除用户")
//	@ApiImplicitParam(name = "id", value = "用户ID", required = true, dataType = "long")
	@DeleteMapping(value = "/delete/{id}")
	public void delete(@PathVariable("id") String id) {
		user1Mapper.deleteById(id);
	}
	
	


}